use std::mem::MaybeUninit;

use sqlx::SqlitePool;

use crate::{cfg::DB_PATH, error::SqlxErr};

pub mod user;
pub mod dev_type;
pub mod dev_file;

static mut POOL: MaybeUninit<SqlitePool> = MaybeUninit::uninit();


pub async fn init() -> Result<(), SqlxErr> {
    let url = format!("sqlite://{}?mode=rwc", DB_PATH);
    let pool = SqlitePool::connect(&url).await?;
    unsafe { POOL.write(pool); }
    user::init().await?;
    dev_type::init().await?;
    dev_file::init().await?;
    Ok(())
}

#[inline(always)]
pub fn get_pool() -> &'static SqlitePool {
    unsafe { POOL.assume_init_ref() }
}









